import nodemailer from 'nodemailer'

const transporter = nodemailer.createTransport({
  service: process.env.EMAIL_SERVICE,
  auth: {
    user: process.env.EMAIL_USER,
    pass: process.env.EMAIL_PASS
  }
});

function send(to: string, code: number) {
  return transporter.sendMail({
    from: process.env.EMAIL_USER,
    to,
    subject: "邮箱验证 - EasyChat",
    html: `
      <div style="font-family: Arial, sans-serif; max-width: 600px; margin: 0 auto;">
        <h1 style="color: #2563eb;">EasyChat 注册验证</h1>
        <p>您好！</p>
        <p>您正在注册 EasyChat 账号，验证码为：</p>
        
        <div style="background: #f3f4f6; padding: 16px; text-align: center; margin: 20px 0; font-size: 24px; font-weight: bold; color: #2563eb;">
          ${code}
        </div>
        
        <p>该验证码将在 <strong>5分钟</strong> 后失效，请尽快使用。</p>
        <p>如非本人操作，请忽略此邮件。</p>
        
        <hr style="border: none; border-top: 1px solid #e5e7eb; margin: 20px 0;">
        
        <p style="font-size: 12px; color: #6b7280;">
          © ${new Date().getFullYear()} EasyChat 团队
        </p>
      </div>
    `,
    text: `您正在注册EasyChat,验证码是 ${code},有效期5分钟。`
  });
}

export default send